<?

//Data loading
$title='CHART OF ACCOUNT';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI PRAYASA CARGO';
$page   = 'PAGE';

$DEFINE_FONT=0;
$pdf=new COAPDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = COAList ("", "", "");
$pdf->COATable($Result);
$pdf->Output();


function COAList ($Space, $Index, $ParentID) {
            global $RS,$Index,$DBConnection;
            if (!$Index) $Index = 0;
            //$DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
            if (strlen($ParentID)) $WHERE = "WHERE parent='$ParentID' ";
//          else $WHERE = "WHERE ifnull(parent,'') = '' ";
            else $WHERE = "WHERE ifnull(parent,'')<> ''";
            if (GetParam("office","")) $WHERE .=  "AND ktrasl='".GetParam("office","")."'";
            if (GetParam("y","")) $WHERE .=  "AND ledger='".GetParam("y","")."'";
            $SQL = "SELECT ktrasl,skada,namacc,skadaold,parent FROM tblcoa ".$WHERE." ORDER BY skada";
            //die($SQL);
            $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
            if ($MyResult){
                foreach ($MyResult as $RowResult) {
//                  if ($RowResult["parent_module_id"]=='') $RowResult["module_name"] = "<b>".$RowResult["module_name"]."</b>";
                    $RowResult["namacc"] = $Space.$RowResult["namacc"];
//                  print $RowResult["namacc"]."  ".$RowResult["skada"]."<br>\n\n";
                    $RS[$Index] = $RowResult;
//                  print $RS[$Index]["module_name"]."$Index<br>\n\n";
                    $Index++;
                    COAList ($Space."      ", $Index, $RowResult["skada"]);
                }
            }
        return $RS;
}



class COAPDFReport extends PDF {

    function Header() {
        global $title,$perush,$page,$DEFINE_FONT;
        if ($DEFINE_FONT==0) {
            $this->AddFont('arialn','','arialn.php');
            $DEFINE_FONT=1;
        }
        $this->SetFont('arialn','',12);
        $this->Cell(180,5,$perush,0,1,'C',0);
        $this->Cell(180,5,$title,0,1,'C',0);
        $this->Cell(180,5,"REPORT DATE: ".date("d/m/y"),0,1,'C',0);
        $this->Cell(180,5,$page." ".$this->PageNo(),0,1,'R',0);
        $this->Line(10,30,190,30);
        $this->Ln();
        $this->Ln();
        //Header
        //Column widths
        $w=array(40,100,40);
        $this->SetFont('arialn','',10);
        $this->Cell($w[0],7,"SKADA",1,0,'C',0);
        $this->Cell($w[1],7,"NAMACC",1,0,'C',0);
        $this->Cell($w[2],7,"SKADA LAMA",1,0,'C',0);
        $this->Ln();
    }

    function COATable($Result) {
        //Column widths
        $w=array(40,100,40);
        //Data
            if ($Result)
        foreach($Result as $row)
        {

            $this->Cell($w[0],6,$row["ktrasl"]."-".$row["skada"],'LR');
            $this->Cell($w[1],6,$row["namacc"],'LR');
            $this->Cell($w[2],6,$row["skadaold"],'LR',0,'R');
            $this->Ln();
        }
        //Closure line
        //$this->Cell(array_sum($w),0,'','T');
    }

    function Footer() {
        //Closure line
        $this->Cell(180,0,'','T');
    }

}


?>
